#include <iostream>
#include <string.h>
#include <string>
#include "defines.h"
#include "statefactory.h"
#include "transition.h"

TransitionTarget *StateFactory::buildState(pugi::xml_node &node,
					   TransitionTarget *parent)
{
  TransitionTarget *result=NULL;

  //std::cout << "build node? " << node.name() <<" = " << node.value() << std::endl;
  std::string name=node.name();
  pugi::xml_attribute_iterator ait;
  // std::cout << "new state id=" << node.attribute("id").value() << std::endl;
  // std::cout << "Attrs" << std::endl;
  // for ( ait = node.attributes_begin(); ait != node.attributes_end(); ++ait)
  //   {
  //       std::cout << " " << ait->name() << "=" << ait->value();
  //   }

  // std::cout << std::endl;

  // if (node.name() == STATE_STR || node.name() == PARALLEL_STR)
  //   {

  result = new State(node.attribute("id").value(), parent);
  result->type = typeMap[node.name()];
  if (parent)
    {
      parent->children.push_back(result);
      //parent->m_children[result->id] = result;
      // adjust parent's type
      if (parent->type == TransitionTarget::Atomic && parent->children.size()>1)
	  parent->type =  TransitionTarget::Compound;
    }
  // }
  return result;
}

Transition *StateFactory::buildTransition(std::string source, std::string dest, 
					  std::string event, std::string cond)
{
  Transition *t;
  //cout << "New transition: from " << source << " to " << dest << endl;
  t = new Transition(source, dest, event, cond);
  return t;
}
